package written.test;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/4  20:22
 * @Description:
 */
public class Tencent2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int i = 0; i < T; i++){
            int n = sc.nextInt();
            int[] arr = new int[n+1];
            for(int j = 1; j <= n; j++) arr[j] = sc.nextInt();
            System.out.println(cal(arr));
        }

    }
    public static int cal(int[] nums){
        Arrays.sort(nums);
        int result = 0;
        int stay = nums.length-1;
        while(stay > 3){
            if(nums[1] + nums[stay-1] > 2*nums[2]) {
                // 第二种方案
                result += 2*nums[2] + nums[stay] + nums[1];
            } else {
                // 第一种方案
                result += 2*nums[1] + nums[stay] + nums[stay-1];
            }
            stay -= 2;
        }
        if (stay == 3){
            result += (nums[1] + nums[2] + nums[3]);
        } else {
            result += (nums[2]);
        }
        return result;
    }
}
